<template>
  <div>
    <div style="position: absolute;background-color: #3474ff;width: 100%;height: 180px;overflow: hidden;">
      <div style="width: 100%;">
<!--        <van-icon-->
<!--            style="position:fixed;top: 20px;left: 20px;cursor: pointer;background-color: #5d90ff;border-radius: 50%"-->
<!--            name="arrow-left" color="white"-->
<!--            size="30px" @click="back"/>-->
        <p style="color: white;font-size: 16px;width: 100%;margin: 10px auto;">登录</p>
      </div>
      <p style="color: white;font-size: 24px;font-weight: 700;margin: 60px 200px 10px 10px;">嗨, 欢迎回来!</p>
      <p style="color: white;font-size: 12px;margin: 10px 170px 10px 10px;">请填写好您的信息已便继续使用</p>
    </div>


    <div align="left" style="width: 100%;margin-top: 200px;">
      <div class="login-container">
        <p style="width: 80%;">手机号:</p>
        <el-input v-model="form.phone" placeholder="请输入手机号" style="width: 80%;margin: 10px auto;"/>
      </div>
      <div class="login-container">
        <p style="width: 80%;">验证码:</p>
        <div style="width: 80%;">
          <el-input v-model="form.code" placeholder="请输入验证码" style="width: 60%;margin: 10px auto;"/>
          <el-button type="primary" @click="getCode" style="width: 40%;">获取验证码</el-button>
        </div>
      </div>
      <div class="login-container">
        <el-button type="primary" @click="onSubmit" style="width: 80%;margin: 10px auto;">登录/注册</el-button>
      </div>
    </div>

    <div style="margin: 160px auto;">
      <p>
        <span style="color: #d1d1d1;">———————— </span>
        <span>第三方登录</span>
        <span style="color: #d1d1d1;"> ————————</span>
      </p>
      <div style="width: 100%;margin: 10px auto;">
        <img
            src="http://sq4f6kqu8.hn-bkt.clouddn.com/rentalcars/QQ.png?e=1736995650&token=rWxRhgEIi6r6WpeIwlvhTEPMnsDCB8KqZ34tVS7A:CnBJWESOK4YfiXxwDYE7baFsMIU="
            width="40px">
        <img
            style="margin-left: 20px"
            src="http://sq4f6kqu8.hn-bkt.clouddn.com/rentalcars/%E5%BE%AE%E4%BF%A1.png?e=1736995710&token=rWxRhgEIi6r6WpeIwlvhTEPMnsDCB8KqZ34tVS7A:jsXUDePV45A1PX3gAstOaPq6KBs="
            width="40px">
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue';
import {Field} from 'vant';

Vue.use(Field);
export default {
  name: "LoginView",
  data() {
    return {
      form: {
        phone: '',
        code: ''
      }
    }
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    getCode() {
      if (this.form.phone == '') {
        this.$message.error("手机号不能为空");
        return;
      }
      var phone = this.form.phone;
      var reg = /^1[3-9]\d{9}$/;
      if (!reg.test(phone)) {
        this.$message.error("手机号格式不正确");
        return;
      }
      this.axios.get(`http://localhost:10086/api/user/users/getCode/` + this.form.phone).then(res => {
        console.log(res.data.message);
        if (res.data.code == 200) {
          this.$message.success("发送成功,验证码是：" + res.data.data)
        } else {
          console.log(res);
          this.$message.error(res.data.message);
        }
      })
    },
    onSubmit() {
      this.axios.get(`http://localhost:10086/api/user/users/login/` + this.form.phone + "/" + this.form.code).then(res => {
        if (res.data.code == 200) {
          console.log(res);
          this.$message.success("登陆成功");
          var user = res.data.data;
          localStorage.setItem("currentUser", JSON.stringify(user));
          setTimeout(() => {
            this.$router.push('/my')
          }, 666)
        } else {
          console.log(res);
          this.$message.error(res.data.message);
        }

      })
    }
  }
}
</script>

<style scoped>
* {
  margin: 0;
  padding: 0;
}

.login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

</style>